package com.oa.admin.service.impl;

import com.joneying.common.annotation.CommonService;
import com.oa.admin.dto.SubsidyListDTO;
import com.oa.admin.vo.SupplierListVO;
import com.oa.admin.vo.SupplierVO;
import com.oa.core.PageResult;
import com.oa.admin.entity.Supplier;
import com.oa.admin.mapper.SupplierMapper;
import com.oa.admin.service.ISupplierService;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.plugins.Page;
import java.util.List;

/**
 * <p>
 * 供应商管理表 服务实现类
 * </p>
 *
 * @author syb123
 * @since 2019-01-22
 */
@Service
public class SupplierServiceImpl extends ServiceImpl<SupplierMapper, Supplier> implements ISupplierService {

    private final SupplierMapper supplierMapper;

    @Autowired
    public SupplierServiceImpl(SupplierMapper supplierMapper) {
        this.supplierMapper = supplierMapper;
    }

    @Override
    @CommonService
    public PageResult<Supplier> findList(Integer pageNum, Integer pageSize) {
        if(pageNum == null){
            List<Supplier> list = supplierMapper.findList();
            return new PageResult<>(list);
        }else{
            // 当前页，总条数 构造 page 对象
            Page<Supplier> page = new Page<>(pageNum, pageSize);
            //查询
            List<Supplier> list = supplierMapper.findList(page);
            return new PageResult<>(list);
        }
    }

    /**
    * 根据id查询
    */
    @Override
    @CommonService
    public SupplierVO findById(String id){
        return supplierMapper.findById(id);
    }

    @Override
    public PageResult<SupplierListVO> findSubsidyList(SubsidyListDTO subsidyListDTO) {
        return new PageResult<>(supplierMapper.findSubsidyList(subsidyListDTO.getPage(), subsidyListDTO));
    }
}
